package cn.codecrab.ai.langchain4j.controller;

import cn.codecrab.ai.langchain4j.mongo.entity.ChatMessages;
import cn.codecrab.ai.langchain4j.mongo.service.ChatMessagesService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author 王刚
 * @since 2025年05月10日 15:30
 */
@RestController
@RequestMapping("/mongo")
public class MongoController {

    @Resource
    private ChatMessagesService chatMessagesService;

    @GetMapping("/insert")
    public ChatMessages insert() {
        ChatMessages message = new ChatMessages();
        message.setContent("测试");
        chatMessagesService.save(message);
        return message;
    }

    @GetMapping("/{id}")
    public ChatMessages findById(@PathVariable("id") String id) {
        return chatMessagesService.getById(id);
    }

    @GetMapping("/update")
    public boolean updateById(@RequestParam String id, @RequestParam String content) {
        return chatMessagesService.lambdaUpdate().eq(ChatMessages::getId, id).set(ChatMessages::getContent, content).update();
    }

}
